<template>
  <div class="container">
    <div>
      <el-row>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：" :label-width="labelwidth">
              <el-date-picker
                v-model="form.startDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 10.9vw"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="结束日期："  :label-width="labelwidth">
              <el-date-picker
                v-model="form.endDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 10.9vw"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" :label-width="labelwidth">
            <el-form-item label="油脂类型：">
              <el-select v-model="form.valueType" placeholder="请选择">
                <el-option
                  v-for="item in selectType"
                  :key="item.label"
                  :label="item.label"
                  :value="item.label"
                  style="width: 10.9vw"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form ref="form" :model="form" :label-width="labelwidth">
            <el-form-item label="餐饮单位：">
              <el-input
                v-model="form.point"
                placeholder="请输入餐饮单位"
                style="width: 10.9vw"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" :label-width="labelwidth">
            <el-form-item label="收运司机：">
              <el-input
                v-model="form.driver"
                placeholder="请输入收运司机"
                style="width: 10.9vw"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" :label-width="labelwidth">
            <el-form-item label="收运车辆：">
              <el-input
                v-model="form.car"
                placeholder="请输入收运车辆"
                style="width: 10.9vw"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <!-- 称重点位	称重时间	称重量	油脂类型	收运车辆	负责司机 -->
      <el-table-column
        prop="称重点位"
        label="餐饮单位名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="称重时间"
        label="称重时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="称重量"
        label="上传重量（KG）"
        align="center"
        :formatter="formatterWeight"
      ></el-table-column>
      <el-table-column prop="油脂类型" label="油脂类型"></el-table-column>
      <el-table-column prop="负责司机" label="收运司机"></el-table-column>
      <el-table-column prop="收运车辆" label="收运车辆"></el-table-column>
      <!-- <el-table-column prop="RubbishType" label="油脂类型"></el-table-column> -->
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
// import '../../assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      selectCompanyType: [{
        value: '全部',
        label: '全部'
      }, {
        value: '3',
        label: '大中型餐饮单位'
      }, {
        value: '2',
        label: '沿街小型商铺'
      }, {
        value: '1',
        label: '小区'
      }],
      selectType: [{
        value: '',
        label: '全部'
      }, {
        value: '1',
        label: '煎炸油'
      }, {
        value: '2',
        label: '隔离油'
      }, {
        value: '3',
        label: '动物油'
      }, {
        value: '4',
        label: '潲水油'
      }, {
        value: '5',
        label: '地沟油'
      }],
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        startDate: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 30), 'yyyy-MM-dd hh:mm:ss'),
        endDate: formatDate(new Date(new Date().getTime() + 3600 * 1000 * 24), 'yyyy-MM-dd hh:mm:ss'),
        radioData: '日',
        valueDay: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: formatDate(new Date(), 'yyyy-MM'),
        valueCompanyType: '',
        valueType: '全部',
        point: '',
        driver: '',
        car: '',
      },
      tableData: []

    }
  },
  created () {
    this.getlistdata();
  },
  methods: {
    async getlistdata () {
      this.currentPage = 1;
      var url = '/VehicleOil/GetWeightHistoryInfo_FYZ?StartDate=' + this.form.startDate + '&EndDate=' + this.form.endDate
      const { data } = await this.$Http.get(url)
      this.tableData = data
      if (this.form.valueType != '全部') {
        this.tableData = this.tableData.filter(item => item.油脂类型 === this.form.valueType)
      }
      if (this.form.point) this.tableData = this.tableData.filter(item => item.称重点位.includes(this.form.point))
      if (this.form.driver) this.tableData = this.tableData.filter(item => item.负责司机.includes(this.form.driver))
      if (this.form.car) this.tableData = this.tableData.filter(item => item.收运车辆.includes(this.form.car))

    },
    // 导出Excel
    exportExcel () {
      let excelName = '台秤称重统计'
      // 称重点位	称重时间	称重量	油脂类型	收运车辆	负责司机
      const tHeader = ['称重点位', '称重时间', '上传重量（KG）', '油脂类型', '收运司机', '收运车辆']
      const filterVal = ['称重点位', '称重时间', '称重量', '油脂类型', '负责司机', '收运车辆']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    formatterWeight (row) {
      return row.称重量 + ' kg'
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>